<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>weaving-compile-time-ant-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>
        <maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <exec.maven.plugin.version>3.1.0</exec.maven.plugin.version>
        <maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
        <java.version>11</java.version>
        <junit5.version>5.9.3</junit5.version>
        <aspectj.version>1.9.7</aspectj.version>
        <maven.surefire.plugin.version>3.1.2</maven.surefire.plugin.version>
        <maven.antrun.plugin.version>1.3</maven.antrun.plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit5.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <excludes>
                        <!-- Отключение компиляции всех файлов в текущем плагине для их компиляции в maven-antrun-plugin -->
                        <exclude>**/*.*</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <!-- Дополнительный плагин, использующийся вместо maven-compiler-plugin с настроенным плетением аспектов -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>${maven.antrun.plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>

                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo>AntRun: Compiling AspectJ classes with ajc, java.home=${java.home}</echo>
                                <taskdef
                                        resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
                                        classpathref="maven.plugin.classpath"/>
                                <iajc
                                        srcDir="src/main/java"
                                        destDir="target/classes"
                                        verbose="true"
                                        showWeaveInfo="true"
                                        source="11"
                                        classpathRef="maven.compile.classpath"
                                        Xlint="ignore">

                                    <exclude name="ru/aspect/ExcludeExampleAspect.java"/>
                                </iajc>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${exec.maven.plugin.version}</version>
                <configuration>
                    <mainClass>ru.app.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>